import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//修改elementPlus默认中文
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
// 引入ElementPlus组件库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 引入图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
//配置根路径
const BASE_URL = 'http://localhost:8080';
//window里面添加的内容是全局内容，可以在任意script标签内部使用
window.BASE_URL = BASE_URL;

const app = createApp(App)
//在VUE实例中也要添加全局内容,BASE_URL才可以在template标签内部使用
app.config.globalProperties.BASE_URL = BASE_URL;
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
//解决页面大小报错问题;
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}
//定义获取用户信息的全局方法
window.getUser = ()=>{
    return localStorage.user?JSON.parse(localStorage.user):null;
}
app.use(ElementPlus,{ locale: zhCn }).use(store).use(router).mount('#app')
